package handler

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	"meituan-sys/cache"
	"meituan-sys/models"
	"time"
)

func List(c *gin.Context) {
	var data []models.User
	redis_list_key := "list_key"
	result, _ := cache.Rdb.Get(cache.Ctx, redis_list_key).Result()
	if result == "" {
		models.DB.Find(&data)
		jsonData, _ := json.Marshal(&data)
		cache.Rdb.Set(cache.Ctx, redis_list_key, jsonData, time.Hour*2)
	} else {
		json.Unmarshal([]byte(result), &data)
	}
	c.JSON(200, gin.H{
		"code": 200,
		"smg":  "展示成功",
		"data": data,
	})
}
